package com.generic.escape.demo1;

/**
 * 在泛型时，不能使用new、instanceof等，通过引入类型标签来对泛型擦除进行补偿，这意味着你需要显示的传递你的类型的Class对象，
 * 以便你可以在类型表达式中使用它。
 * 
 * 
 * @author Administrator
 * 
 * @param <T>
 */
public class ClassTypeCapture<T> {

	Class<T> kind;

	public ClassTypeCapture(Class<T> kind) {
		this.kind = kind;
	}

	public boolean f(Object arg) {
		return kind.isInstance(arg);
	}

	public static void main(String[] args) {
		ClassTypeCapture<Building> ctt1 = new ClassTypeCapture<Building>(
				Building.class);
		System.out.println(ctt1.f(new Building()));
		System.out.println(ctt1.f(new House()));
		
		ClassTypeCapture<House> ctt2 = new ClassTypeCapture<House>(
				House.class);
		System.out.println(ctt2.f(new Building()));
		System.out.println(ctt2.f(new House()));
	}

}
